/**
 * 版权所有(C)，上海勾芒信息科技，2016，所有权利保留。
 * 
 * 项目名：	carwx
 * 文件名：	FansConverter.java
 * 模块说明：	
 * 修改历史：
 * 2016年11月29日 - Debenson - 创建。
 */
package com.alex.wechat.mp.fans.service;

import org.jeecgframework.web.cgform.common.CgAutoListConstant;
import org.springframework.core.convert.converter.Converter;

import com.alex.wechat.mp.fans.entity.WxFansEntity;

import me.chanjar.weixin.mp.bean.result.WxMpUser;

/**
 * @author Debenson
 * @since 0.1
 */
public class FansConverter implements Converter<WxMpUser, WxFansEntity> {

  private static FansConverter instance;

  public synchronized static FansConverter getInstance() {
    if (instance == null) {
      instance = new FansConverter();
    }
    return instance;
  }

  private FansConverter() {
  }

  @Override
  public WxFansEntity convert(WxMpUser source) {
    if (source == null) {
      return null;
    }

    WxFansEntity dest = new WxFansEntity();
    dest.setOpenid(source.getOpenId());
    dest.setNickname(source.getNickname());
    dest.setSex(source.getSex());
    dest.setCity(source.getCity());
    dest.setCountry(source.getCountry());
    dest.setProvince(source.getProvince());
    dest.setLanguage(source.getLanguage());
    dest.setHeadimgurl(source.getHeadImgUrl());
    dest.setSubscribeTime(source.getSubscribeTime());
    dest.setSubscribe(source.getSubscribe() != null && source.getSubscribe().booleanValue()
        ? CgAutoListConstant.BOOL_TRUE : CgAutoListConstant.BOOL_FALSE);
    dest.setUnionid(source.getUnionId());
    dest.setRemark(source.getRemark());
    dest.setGroupid(source.getGroupId() == null ? null : source.getGroupId().toString());
    return dest;
  }

}
